using System;
using System.Collections.Generic;
using System.Linq;
using ClientCommonWpf;
using Director.DomainModels;
using Xceed.Wpf.AvalonDock.Layout;

namespace Director.ViewModels
{
	abstract class AbstractPaneVM : AbstractViewModel
	{
		public const char SEPEARATOR = ':';
		
		private bool _isActive;
		public abstract string Title { get; }
		public abstract string ContentId { get; }
		public abstract void Init();
		
		private readonly List<Security> _listenCandles = new List<Security>();

		public bool IsActive
		{
			get { return _isActive; }
			set
			{
				_isActive = value;
				OnPropertyChanged(()=>IsActive);
			}
		}

		public RelayCommand CloseCommand { get; private set; }

		protected AbstractPaneVM()
		{
			CloseCommand = new RelayCommand(ExecuteCloseCommand);
		}

		protected abstract void ExecuteCloseCommand(object obj);

		public TimeFrame ListenTimeFrame { get; protected set; }

		public void StartListenCandles(Security security)
		{
			if (!_listenCandles.Contains(security))
			{
				_listenCandles.Add(security);
			}
		}

		public ICollection<Security> ListenSecurities
		{
			get { return _listenCandles; }
		}

		public void StopListenCandles(Security security)
		{
			if (_listenCandles.Contains(security))
			{
				_listenCandles.Remove(security);
			}
		}

		public abstract void CandlesUpdated();

		public abstract void Closed(object sender, EventArgs e);

		public void IsActiveChanged(object sender, EventArgs e)
		{
			if (sender is LayoutAnchorable && ((LayoutAnchorable)sender).IsHidden)
			{
				Closed(sender, e);
			}
		}
	}
}